﻿@model NCLCustomerManagement.UI.Models.User.ChangePasswordModel
@{
    
    Layout = "";
    ViewBag.Title = "ChangePassword";
}


<div id="changePasswordMsgbox" class="alert alert-danger" style="display: none;">

    <div class="msg-content"></div>

</div>
<div class="form-group">
    @Html.LabelFor(model => model.CurrentPassword)
    @Html.TextBoxFor(model => model.CurrentPassword, new { type = "password", @class = "form-control input-sm", placeholder = "Nhập mật khẩu hiện tại mà bạn đang dùng" })
</div>

<div class="form-group">
    @Html.LabelFor(model => model.NewPassword)
    @Html.TextBoxFor(model => model.NewPassword, new { type = "password", @class = "form-control input-sm", placeholder = "Bạn muốn thay đổi thành..." })
</div>

<div class="btn-toolbar">
    <div class="bt-n-group" style="float: right;">
        <button id="btnSave" class="btn btn-primary" onclick="save();"><span class="glyphicon glyphicon-save" title="Lưu">Lưu</span></button>
        <button id="btnCancel" class="btn btn-default" onclick="cancel();"><span class="glyphicon glyphicon-log-out" title="Hủy">Hủy</span></button>
    </div>
</div>

<script>
    function save() {
        var model = getChangePasswordModel();


        $.blockUI();
        var d = JSON.stringify(model);
        $.ajax({
            url: "/User/SubmitChangePassword",
            data: { model: d },
            contentType: 'json',
            dataType: "json",
            type: "get",
            success: function (data) {
                if (!data.Success) {
                    showMessage("#changePasswordMsgbox", data.Message, !data.Success);
                }
                else {
                    showMessage("#alertbox", data.Message, !data.Success);
                    cancel();
                }
                $.unblockUI();
            },
            error: function (data) {
                //window.location.href = "/User/Login";
                $.unblockUI();
            }
        });


        function getChangePasswordModel() {
            return {
                currentPassword: $("#CurrentPassword").val(),
                newPassword: $("#NewPassword").val(),
            };
        }
    }

    function cancel() {
        $('#changePasswordWindow').modal('hide');
    }

</script>
